package xyz.lilei123;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import xyz.lilei123.entity.Resume;
import xyz.lilei123.repository.ResumeRepository;

import java.util.List;

/**
 * @author jack
 * @version 1.0
 * @date 28/11/2021 21:20
 **/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Starter.class)
public class test {

    @Autowired
    private ResumeRepository resumeRepository;


    /**
     * 测试 写
     */
    @Test
    public void testMongoWrite() {
        Resume resume = new Resume();
        resume.setName("jack");
        resume.setExpectSalary(1);
        resume.setCity("bj");
        resumeRepository.save(resume);
    }


    /**
     * 测试读
     */
    @Test
    public void testMongoRead() {
        List<Resume> list = resumeRepository.findByNameEquals("jack");
        list.forEach(resume -> System.out.println(resume.toString()));
        List<Resume> list1 = resumeRepository.findByNameLike("jack");
        list1.forEach(resume -> System.out.println(resume.toString()));
    }


    /**
     * 测试分片
     */
    @Test
    public void testMongoShard() {
        for (int i = 1001; i < 2000; i++) {
            Resume resume = new Resume();
            resume.setName("jack" + i);
            resume.setExpectSalary(i);
            resume.setCity("bj");
            resumeRepository.save(resume);
        }

    }

}
